<head>
<title>个人信息页面</title>
<style type="text/css">
body {
	background-image: url(background2.jpg);
	width:100%;
    height:100%;
}
</style>
</head>

<body>

<?php
//补充：此PHP文件未用到api_userinfo.php

/*---------------------一、PHP文件引用----------------------------------*/
require_once 'response.php';
require_once 'connect_config.php';

/*---------------------二、变量参数定义-------------------------------*/
$i = 0;
$msg = '';
$$roleid = array();
$rolename = array();
$username = $_GET['username'];
$role = "";

/*---------------------三、数据库连接--------------------------------*/
$conn = mysqli_connect(DB_HOST,DB_USER,DB_PWD,DB_NAME,DB_PORT) or die('数据库连接失败');

/*---------------------四、用户信息查询-------------------------------*/
$query1 = "select * from mdl_user where username = '$username'";
$data1 = mysqli_query($conn, $query1);
if ($data1)
{
	$row1 = mysqli_fetch_array($data1);
	$firstname = $row1['firstname'];
	$lastname = $row1['lastname'];
	$password = $row1['password'];
	$email = $row1['email'];
	$country = $row1['country'];
	$city = $row1['city'];
	$userid = $row1['id'];
	$query2 = "select * from mdl_role_assignments where userid = '$userid'";
	$data2 = mysqli_query($conn, $query2);
	if($data2)
	{
		while($row2 = mysqli_fetch_array($data2))
		{
			$roleid[$i] = $row2['roleid'];
			if($roleid[$i] == 1)
			{
				$rolename[$i] = 'manager';
			}
			else if($roleid[$i] == 2)
			{
				$rolename[$i] = 'coursecreator';
			}
			else if($roleid[$i] == 3)
			{
				$rolename[$i] = 'editingteacher';
			}
			else if($roleid[$i] == 4)
			{
				$rolename[$i] = 'teacher';
			}
			else if($roleid[$i] == 5)
			{
				$rolename[$i] = 'student';
			}
			else if($roleid[$i] == 6)
			{
				$rolename[$i] = 'guest';
			}
			else if($roleid[$i] == 76)
			{
				$rolename[$i] = 'user';
			}
			else 
			{
				$rolename[$i] = 'frontpage';
			}
			$role = $role."<br>".$rolename[$i];
			$i++;
		}
		
	}
	else
	{
		$status = false;
		$msg = '用户角色查询失败';	
	}
}
else
{
	$status = false;
	$msg = '用户名查询失败';
	$valuse = array($status,$msg);
}
mysqli_close($conn);

?>
<form action = "userinfo-c.php" method= "POST" align = "center">
<p style="text-align:center;">
  <table width="417" border="1">
    <tr>
      <td width="200">用户名：</td>
      <td width="201"><?=$username?></td>
    </tr>
    <tr>
      <td width="200">姓：</td>
      <td width="201"><?=$firstname?></td>
    </tr>
    <tr>
      <td width="200">名：</td>
      <td width="201"><?=$lastname?></td>
    </tr>
    <tr>
      <td width="200">地区：</td>
      <td width="201"><?=$country?>&nbsp;&nbsp;&nbsp;<?=$city?></td>
    </tr>
    <tr>
      <td>邮箱：</td>
      <td><?=$email?></td>   
    </tr>
    <tr>
      <td>角色：</td>
      <td><?=$role?></td>
    </tr>
    <tr>
      <td colspan="2"align="center"><input name="infochange" type="submit" value="点此修改" /></td>
    </tr>
  </table>
</p>
</form>
<?php
$button = $_POST['infochange'];
$url = 'changeuserinfo-c.php';
if($button)
{
	echo "<script language='javascript' type = 'text/javascript'>";
	echo "window.location.href = '$url'";
	echo"</script>";	
	
}

?>

</body>
</html>
</body>
</html>
